pkgname = "shotman"
pkgver = "0.4.7"
pkgrel = 1
build_style = "cargo"
hostmakedepends = ["cargo-auditable", "pkgconf", "scdoc"]
makedepends = ["libxkbcommon-devel", "rust-std"]
depends = ["slurp"]
pkgdesc = "Screenshot GUI for Wayland"
license = "ISC"
url = "https://sr.ht/~whynothugo/shotman"
source = f"https://git.sr.ht/~whynothugo/shotman/archive/v{pkgver}.tar.gz"
sha256 = "8a2239b37bababcc10db787d931f5d83c3eb254a0f1b30fa5e2d4dd31eff4cc5"
env = {
    "SHOTMAN_VERSION": f"v{pkgver}",
}
# !check because no tests, and !cross because completions are generated by
# running a binary
options = ["!check", "!cross"]


def pre_prepare(self):
    # the version that is in there is busted on loongarch
    self.do(
        "cargo",
        "update",
        "--package",
        "libc",
        "--precise",
        "0.2.170",
        allow_network=True,
    )


def post_build(self):
    self.do("make", "shotman.1")

    for shell in ["bash", "zsh", "fish"]:
        with open(self.cwd / f"shotman.{shell}", "w") as cf:
            self.do(
                f"target/{self.profile().triplet}/release/shotman_completions",
                shell,
                stdout=cf,
            )


def post_install(self):
    self.install_license("LICENCE.md")
    self.install_man("shotman.1")

    self.install_completion("shotman.bash", "bash")
    self.install_completion("shotman.zsh", "zsh")
    self.install_completion("shotman.fish", "fish")
